from selenium import webdriver
from selenium.webdriver import Keys
from selenium.webdriver.common.by import By
import time

def get_next_html():
    pass
try:
    # 创建Chrome选项实例
    option = webdriver.ChromeOptions()
    option.add_experimental_option("detach", True)
    # 使用options参数启动Chrome浏览器
    driver = webdriver.Chrome(options=option)
    # 访问指定的网址
    driver.get('https://www.ccgp-chongqing.gov.cn/info-notice/procument-notice')
    time.sleep(2)
    input_element = driver.find_element(By.NAME,"title")
    input_element.send_keys('物业')
    input_element.send_keys(Keys.RETURN)
    time.sleep(2)
    resp = driver.find_elements(By.XPATH,'//*[@id="ui-view"]/div/div[2]/div/div/div/div[2]/div[3]/div')
    try:
        for i in resp:
            City = i.find_element(By.XPATH,'./div/div[1]/p/span[1]').text #采购城市
            Title = i.find_element(By.XPATH,'./div/div[1]/a').text  #标题
            Purchaser  = i.find_element(By.XPATH,'./div/div[1]/p/span[3]').text   #采购商
            Agency = i.find_element(By.XPATH,'./div/div[1]/p/span[4]').text  #代理机构
            Send_Time = i.find_element(By.XPATH,'./div/div[3]/div/span').text #发布时间
            print("{}， 标题：{}， {}， {}，发布时间：{}".format(City,Title,Purchaser,Agency,Send_Time))

    except Exception as e:
        print(e)
except Exception as e:
    print("访问失败")
    print(f"An error occurred: {e}")
finally:
    # 确保浏览器被关闭
    driver.quit()

